package com.jiudaoliu.homeprototype.controller;

import com.jiudaoliu.homeprototype.entity.ManagerEntity;
import com.jiudaoliu.homeprototype.service.ManagerServie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author chenjian
 * @Package
 * @Description:
 * @date 2018/9/20 11:01
 */
//@RestController
@Controller
public class IndexController {
    @Autowired
    private ManagerServie managerServieImpl;

    /**
     * @Description: 主页跳转
     * @Param: []
     * @Return: java.lang.String
     * @Author: 陈建
     * @date: 2018/9/20 13:38
     */
    @GetMapping(value = "/")
    public String index() {
        return "index";
    }

    /**
     * @Description: 后台数据管理页面跳转
     * @Param: [name]
     * @Return: java.lang.String
     * @Author: 陈建
     * @date: 2018/9/21 11:47
     */
    @GetMapping(value = "/page/manager/{name}")
    public String manage(@PathVariable String name) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (null != name) {
            List<ManagerEntity> list = managerServieImpl.findByName(name);
            if (null != list && list.size() > 0) {
                System.out.println("授权用户:" + name + "在" + format.format(new Date()) + "登录管理页面");
                return "manager";
            }
        }
        return "redirect:/";
    }

    @GetMapping(value = "/test")
    public String test() {
        return "test";
    }

}
